package com.ruiysoft.website.service;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.ruiysoft.website.dto.SysUserEx;
import com.ruiysoft.website.mapper.SysUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by liudh on 2019/4/25.
 */

@Service
public class SysUserService {
    @Autowired
    SysUserMapper sysUserMapper;

    public Object login(String un, String pw) {
        EntityWrapper ew = new EntityWrapper();
        ew.eq("loginName", un)
                .eq("password", pw);

        List list = sysUserMapper.selectList(ew);
        if(list.size() > 0) {
            SysUserEx sysUserEx = JSON.parseObject(JSON.toJSONString(list.get(0)), new TypeReference<SysUserEx>(){});
            sysUserEx.setUuid("1");
            sysUserEx.setToken("2");
            sysUserEx.setName(sysUserEx.getRealName());

            return sysUserEx;
        }
        else
            return null;
    }
}
